package cn.jiyun.service.impl;

import cn.jiyun.mapper.ConstactorMapper;
import cn.jiyun.mapper.DeveloperMapper;
import cn.jiyun.mapper.ProjectMapper;
import cn.jiyun.pojo.Constactor;
import cn.jiyun.pojo.Developer;
import cn.jiyun.pojo.Project;
import cn.jiyun.result.QueryPageBean;
import cn.jiyun.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class ProjectServiceimpl implements ProjectService {

    @Autowired
    private ProjectMapper projectMapper;

    @Autowired
    private DeveloperMapper developerMapper;

    @Autowired
    private ConstactorMapper constactorMapper;


    @Override
    public List<Map> findPage(QueryPageBean queryPageBean) {
        List<Map> list = projectMapper.findPage((queryPageBean.getCurrentPage() - 1) * queryPageBean.getPageSize(), queryPageBean.getPageSize(), queryPageBean.getQueryString());
        return list;
    }

    @Override
    public int jilu() {
        return projectMapper.jilu();
    }

    @Override
    public int add(Project project) {
        project.setUpdatetime(new Date());
        return projectMapper.add(project);
    }

    @Override
    public void delete(Integer pid) {
        projectMapper.delete(pid);
    }

    @Override
    public List<Project> findById(Integer pid) {
        return projectMapper.findById(pid);
    }

    @Override
    public int edit(Project project) {
        return projectMapper.edit(project);
    }

    @Override
    public List<Developer> init() {
        return developerMapper.init();
    }

    @Override
    public List<Constactor> init2() {
        return constactorMapper.init2();
    }

    @Override
    public List<Project> init3() {
        return projectMapper.init3();
    }

    @Transactional
    @Override
    public long flag(Developer developer, int[] ids) {
        String did = developer.getDid();
        long a = 0L;
        for (int pid : ids) {
            int i = projectMapper.flag(did, pid);
            a++;
        }
        return a;
    }
}
